<template>
  <div class="app">
    <div class="title">收藏列表</div>
    <div class="desc" v-if="catoonList.length == 0">快去追番吧</div>
    <div class="app-item">
      <div class="catoon" v-for="c in catoonList" :key="c.storyId">
        <div
          class="img"
          @click="
            gocatoon(c.storyId, c.contentId, c.storyImg, c.count, c.author)
          "
        >
          <button class="dele" @click.stop="dele(c.storyId)">x</button>
          <img :src="c.storyImg" alt="" />
        </div>
        <transition name="scrollX">
          <router-view />
        </transition>
      </div>
    </div>
  </div>
</template>

<script>
import { debounce } from "lodash-es";
export default {
  name: "CatoonView",
  data() {
    return {
      catoonList: [],
    };
  },

  created() {
    this.getData = debounce(this.getData);
  },
  mounted() {
    this.getData();
  },

  methods: {
    dele(id) {
      let catoonList = localStorage.catoonList
        ? JSON.parse(localStorage.catoonList)
        : [];
      let newlist = catoonList.filter((c) => c.storyId != id);
      localStorage.catoonList = JSON.stringify(newlist);
      this.$router.go(0);
      
    },
    gocatoon(sid, img) {
     
        if (this.$route.name == `catoon/catoonstory`) {
          this.$router.go(-1);
        } else {
          this.$router.push({
            name: `catoonstory`,
          });
        }
        sessionStorage.storyList = JSON.stringify({
          id: sid,
          route: "catoon",
          img,
        });
      
    },
    getData() {
      if (localStorage.catoonList) {
        this.catoonList = localStorage.catoonList
          ? JSON.parse(localStorage.catoonList)
          : [];
        //  console.log(this.catoonList);
      } else {
        return;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.app {
  position: fixed;
  height: 100vh;
  width: 100vw;
  top: 55px;
  // left:40px;
  overflow: auto;
  padding-bottom: 50px;
  // display: flex;
  justify-content: space-around;
  background-color: white;
  z-index: 999;

  .title {
    width: 100vw;
    height: 20px;
    position: absolute;
    text-align: center;
    border-bottom: 1px solid rgb(156, 152, 152, 0.4);
    font-size: 18px;
    color: rgb(156, 152, 152, 0.6);
    top: 10px;
  }

  .desc {
    width: 100vw;
    height: 20px;
    position: absolute;
    text-align: center;
    font-size: 18px;
    color: rgb(156, 152, 152, 0.6);
    top: 240px;
  }

  .img {
    float: left;
    position: relative;
    top: 50px;
    width: 150px;
    height: 100px;
    margin-bottom: 20px;
    border-radius: 30px;
    margin-left: 80px;

    box-shadow: 7px 7px 12px rgba(0, 0, 0, 0.4),
      -7px -7px 12px rgba(255, 255, 255, 0.9);

    .dele {
      position: absolute;
      top: 0;
      right: -26%;
      border: 0;
      border-radius: 999px;
      width: 40px;
      height: 40px;
    }
    img {
      width: 100%;
      height: 100%;
      border-radius: 30px;
    }
  }
}

.scrollX-enter,
.scrollX-leave-to {
  left: 0;
  top: 0;
  right: 0;
  position: absolute;
  transform: translateY(100%);
  opacity: 0;
}
.scrollX-enter-active {
  transition: all 0.7s ease;
}
.scrollX-leave {
  transform: translateY(-100%);
  opacity: 1;
}
.scrollX-enter-to {
  transform: translateY(0);
  opacity: 1;
}
.scrollX-leave-active {
  transition: all 0.7s ease;

  z-index: 100;
}
</style>